Ext.define('iMedproplus.view.admin.user.PasswordForm', {
    extend: 'Ext.window.Window',
    alias: 'widget.adminuserpasswordform',
    title: 'Zmiana hasła',
    modal: true,
    width: 400,
    layout: {
        align: 'stretch',
        type: 'vbox'
    },
    
    initComponent: function() {
        var me = this;
        Ext.applyIf(me, {
            items: [
            {
                xtype: 'form',
                layout: 'form',
                bodyPadding: 10,
                border : 0,
                items: [
                {
                    xtype: 'textfield',
                    name: 'password1',
                    fieldLabel: 'Has\u0142o',
                    inputType: 'password',
                    allowBlank: false,
                    minLength: 8
                }, {
                    xtype: 'textfield',
                    name: 'password2',
                    fieldLabel: 'Powtórz has\u0142o',
                    inputType: 'password',
                    allowBlank: false,
                    validator: function(value) {
                        var password1 = this.previousSibling('[name=password1]');
                        return (value === password1.getValue()) ? true : 'Has\u0142a nie są identyczne.'
                    }
                }
                ],
                buttons: [
                {
                    text: 'Zmie\u0144',
                    handler: function() {
                        var form = this.up('form').getForm();
                        if(form.isValid()){
                            form.submit({
                                clientValidation: true,
                                method:'GET',
                                url: '/imedproplus-rest/rest/json/user/password',
                                params: {
                                    userId: Ext.App.getController('iMedproplus.controller.admin.User').currentUser.id
                                },
                                success: function(form, action) {
                                    Ext.Msg.alert('Uwaga', 'Has\u0142o poprawnie zmienione!');
                                    Ext.App.getController('iMedproplus.controller.admin.User').passwordWinow.close();
                                },
                                failure: function(form, action) {
                                    Ext.Msg.alert('Uwaga', 'Nie uda\u0142o się zmienić hasła.');
                                },
                                scope : this
                            });
                        }
                    }
                }
                ]
            }
            ]
        });
        me.callParent(arguments);
    }

});